package com.caiyouxi.finance.service;

import com.caiyouxi.common.service.BaseService;
import com.caiyouxi.finance.mapper.FinanceTradeReceivedMapper;
import com.caiyouxi.finance.model.FinanceTradeReceived;
import com.caiyouxi.util.NumUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.math.BigInteger;
import java.util.Date;
import java.util.HashMap;


/**
 * 应收应付流水记录
 * chensong
 */
@Service
public class FinanceTradeReceivedService extends BaseService {
    
    @Autowired
    private FinanceTradeReceivedMapper financeTradeReceivedMapper;

    public FinanceTradeReceived add_finance_trade_received(Integer amount,BigInteger ftrd_id,BigInteger ftr_id,String status){
        FinanceTradeReceived ftrd = new FinanceTradeReceived();
        ftrd.setId(new BigInteger(NumUtil.generate_number(3)));
        ftrd.setAmount(amount);
        ftrd.setFinance_trade_details_id(ftrd_id);
        ftrd.setFinance_trade_receivable_id(ftr_id);
        ftrd.setStatus(status);//生成/处理中
        ftrd.setCreate_time(new Date());
        ftrd.setUpdate_time(new Date());
        financeTradeReceivedMapper.add_finance_trade_received(ftrd);
        return ftrd;
    }
    
    public void update_finance_trade_received(FinanceTradeReceived ftr){
        financeTradeReceivedMapper.update_finance_trade_received(ftr);
    }

    /**
     * 更新应收应付流水记录信息状态
     */
    public void update_finance_trade_received_by_status(FinanceTradeReceived ftrd){
        //更新应收应付记录状态
        ftrd.setUpdate_time(new Date());
        update_finance_trade_received(ftrd);
    }

    public FinanceTradeReceived select_finance_trade_received_by_receivable_id_and_details_id(HashMap<String,Object> map){
        return financeTradeReceivedMapper.select_finance_trade_received_by_receivable_id_and_details_id(map);
    }
}
